<?php
require '../script/mysqlconfig.php';
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
    die("连接数据库失败: " . $conn->connect_error);
}
//处理提交的表单
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $id = $_POST["id"];
    $brand = $_POST["brand"];
    $model = $_POST["model"];
    $serial_number = $_POST["serial_number"];
    $device_type = $_POST["device_type"];
    $room = $_POST["room"];
    $cabinet = $_POST["cabinet"];
    $start_u = $_POST["start_u"];
    $end_u = $_POST["end_u"];
    $device_status = $_POST["device_status"];
    $device_feature = $_POST["device_feature"];
    $bmc_ip = $_POST["bmc_ip"];
    $manage_ip = $_POST["manage_ip"];
    $yewu_ip = $_POST["yewu_ip"];
    $device_belong = $_POST["device_belong"];
    $belong_en = $_POST["belong_en"];
    $belong_op = $_POST["belong_op"];
    $asset_code = $_POST["asset_code"];
    $use_en = $_POST["use_en"];
    $use_operator = $_POST["use_operator"];
    $client_no = $_POST["client_no"];
    $client_name = $_POST["client_name"];
    $other = $_POST["other"];
    $result = mysqli_query($conn, "UPDATE `hosts` SET `brand`='$brand', `model`='$model', `serial_number`='$serial_number', `device_type` = '$device_type', `room` = '$room', `cabinet` = '$cabinet', `start_u` = '$start_u', `end_u` = '$end_u', `device_status` = '$device_status', `device_feature` = '$device_feature', `bmc_ip` = '$bmc_ip', `manage_ip` = '$manage_ip', `yewu_ip` = '$yewu_ip', `device_belong` = '$device_belong', `belong_en` = '$belong_en', `belong_op` = '$belong_op', `asset_code` = '$asset_code', `use_en` = '$use_en', `use_operator` = '$use_operator', `client_no` = '$client_no', `client_name` = '$client_name', `other` = '$other' WHERE `id`='$id' ");

    if ($result == true) {
        echo "设备信息更新成功";
    } else {
        echo "设备信息更新失败" . "<br/>" . $conn->error;
    }
}
//获取要编辑的数据
$id = $_GET["id"];
$result = mysqli_query($conn, "SELECT * FROM hosts WHERE id='$id' ");
$row = mysqli_fetch_assoc($result);
//输出表单
echo "<form method='POST' enctype='multipart/form-data'>";
echo "<input type='hidden' name='id' value='".$row['id']."'>";
echo "<table border='1' style='width:1130px;border-collapse:collapse;'>";
echo "<tr>";
echo "<td align='right'>品牌:<input type='text' name='brand' value='".$row['brand']."'></td>";
echo "<td align='right'>型号:<input type='text' name='model' value='".$row['model']."'></td>";
echo "<td align='right'>序列号:<input type='text' name='serial_number' value='".$row['serial_number']."'></td>";
//echo "<td align='right'>设备类型:<input type='text' name='device_type' value='".$row["device_type"]."'></td>";
echo "<td align='right'>设备类型:<select name='device_type'> <option  selected='".$row["device_type"]."'>".$row["device_type"]."</option> <option value='服务器'>服务器</option> <option value='存储'>存储</option> <option value='交换机'>交换机</option> <option value='路由器'>路由器</option> <option value='防火墙'>防火墙</option> <option value='安全设备'>安全设备</option> <option value=0>------------请选择------------</option></select></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right'>所在机房:<input type='text' name='room' value='".$row["room"]."'></td>";
echo "<td align='right'>机柜:<input type='text' name='cabinet' value='".$row["cabinet"]."'></td>";
echo "<td align='right'>开始U位:<input type='text' name='start_u' value='".$row["start_u"]."'></td>";
echo "<td align='right'>结束U位:<input type='text' name='end_u' value='".$row["end_u"]."'></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right'>使用状态:<input type='text' name='device_status' value='".$row["device_status"]."'></td>";
echo "<td align='right'>设备用途:<input type='text' name='device_feature' value='".$row["device_feature"]."'></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right'>带外IP:<input type='text' name='bmc_ip' value='".$row["bmc_ip"]."'></td>";
echo "<td align='right'>管理IP:<input type='text' name='manage_ip' value='".$row["manage_ip"]."'></td>";
echo "<td align='right'>业务IP:<input type='text' name='yewu_ip' value='".$row["yewu_ip"]."'></td>";
echo "</tr>";
echo "<tr>";
//echo "<td align='right'>资产归属类型:<input type='text' name='device_belong' value='".$row["device_belong"]."'></td>";
echo "<td align='right'>资产归属类型:<select name='device_belong'> <option  selected='".$row["device_belong"]."'>".$row["device_belong"]."</option> <option value='公司自有'>公司自有</option> <option value='业务单位自有'>业务单位自有</option> <option value='客户自有'>客户自有</option> <option value='厂商借测'>厂商借测</option> <option value=0>------------请选择------------</option> </select></td>";
echo "<td align='right'>资产归属部门:<input type='text' name='belong_en' value='".$row["belong_en"]."'></td>";
echo "<td align='right'>资产归属人员:<input type='text' name='belong_op' value='".$row["belong_op"]."'></td>";
echo "<td align='right'>公司资产编码:<input type='text' name='asset_code' value='".$row["asset_code"]."'></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right'>设备使用部门:<input type='text' name='use_en' value='".$row["use_en"]."'></td>";
echo "<td align='right'>设备使用人:<input type='text' name='use_operator' value='".$row["use_operator"]."'></td>";
echo "<td align='right'>客户号:<input type='text' name='client_no' value='".$row["client_no"]."'></td>";
echo "<td align='right'>客户名字:<input type='text' name='client_name' value='".$row["client_name"]."'></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right'>备注:<input type='text' name='other' value='".$row["other"]."'></td>";
echo "</tr>";
echo "</table>";
echo "<input type='submit' value='保存更新'>";
echo "</form>";

mysqli_close($conn);
